package com.kangkang.leetcode20;

import java.util.Locale;
import java.util.regex.Pattern;

public class Test125 {
    public static void main(String[] args) {
        System.out.println(new Solution125().isPalindrome("A man, a plan, a canal: Panama"));
    }

}
class Solution125 {
    public boolean isPalindrome(String s) {

        s = s.toLowerCase();
        int right = s.length()-1;
        int left = 0;

        while (right>left){
            while (right>left&&!Character.isLetterOrDigit(s.charAt(right))){
                    right--;
            }
            while (right>left&&!Character.isLetterOrDigit(s.charAt(left))){
                left++;
            }
            if(s.charAt(right)!=s.charAt(left)){
                return false;
             }else {
                right--;
                left++;
            }
        }
            return true;
        }

}